﻿@using Gurux.DLMS.AMI.Shared.DTOs

@if (Target?.Attributes != null && Target.Template != null && Target.Attributes.Any())
{
    <CascadingValue Value="this">
        <AttributeTile Index="0" Name="@Properties.Resources.Description" Text="@Target.Template.Name"></AttributeTile>
        <AttributeTile Index="1" Name="@Properties.Resources.LogicalName" Text="@Target.Template.LogicalName"></AttributeTile>
        <AttributeTile Index="2" Attributes="@Target.Attributes"></AttributeTile>
        @ChildContent
    </CascadingValue>
}

@code {

    [Parameter]
    public RenderFragment? ChildContent { get; set; }

    [CascadingParameter]
    private ObjectView? Parent { get; set; }

    /// <summary>
    /// Target COSEM object.
    ///</summary>
    [Parameter]
    public GXObject? Target { get; set; }

    protected override void OnInitialized()
    {
        if (Parent == null)
            throw new ArgumentNullException(nameof(Parent), "View must exist within a Object view");
        base.OnInitialized();
    }
}